<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/14 0014
 * Time: 10:11
 */

namespace app\mobile\controller;

use app\model\model\Ad;
use app\model\model\Label;
use app\model\model\Seo;
use app\model\model\Video_type;
use think\Request;
class Video extends Base
{
//实例化
    protected $_Seo;
    protected $_Ad;
    protected $_Video;
    protected $_Video_type;
    protected $_Label;
    public function __construct(Request $request = null){
        parent::__construct($request);
        $this->_Ad = new Ad();
        $this->_Seo = new Seo();
        $this->_Video = new \app\model\model\Video();
        $this->_Video_type = new Video_type();
        $this->_Label = new Label();
    }
    public function index(){
        //SEO
        $seo = $this->_Seo->getOne(['id'=>1]);
        $this->assign('seo',$seo);
        //banner
        $banner = $this->_Ad->getListHome(['type_id'=>37,'flag'=>1]);
        $this->assign('banner',$banner);
        //分类
        $type = $this->_Video_type->getListSelect(true);
        $this->assign('type',$type);
        $this->assign('type_id',input('type'));
        //列表
        $list = $this->_Video->getListSelect(['flag'=>1],true);
        foreach ($list as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
            $v['create_time'] = date('m, Y',$v['create_time']);
        }
        $this->assign('list',$list);
        $index = $this->_Video_type->getOne(11);
        $this->assign('index',$index);
        return $this->fetch();
    }
    public function getListByType(){
        if(input('type')){
            $list = $this->_Video->getListSelect(['type_id'=>input('type'),'flag'=>1],true);
        }else{
            $list = $this->_Video->getListSelect(['flag'=>1],true);
        }
        foreach ($list as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
            $v['create_time'] = date('m, Y',$v['create_time']);
        }
        return json_echo_msg(200,'chenggong',$list);
    }
    public function view(){

        $id = input('name');
        $data = $this->_Video->getOneByName(['id'=>$id]);
        $this->_Video->up(['id'=>$data['id']],['pv'=>($data['pv']+1)]);
        $data['create_time'] = date('m, Y',$data['create_time']);
        $this->assign('data',$data);
        //推荐列表
        $likelist = $this->_Video->getListSelect(['flag'=>1],false,3);
        foreach ($likelist as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
            $v['create_time'] = date('m, Y',$v['create_time']);

        }
        $this->assign('likelist',$likelist);
        //标签列表
        $tags = $this->_Label->getListSelect();
        $this->assign('tags',$tags);

        //上一个  下一个
        $data1 = $this->_Video->getListSelect(['flag'=>1],true);
        $b = [];
        $c = [];
        $id = $data['id'];
        $kk=0;
        foreach ($data1 as $k=>$v){
            if($v['id']==$id){
                $kk = $k;
            }
        }
        foreach ($data1 as $k=>$v){
            if($k==$kk-1){
                $b = $v;
                $b['uname'] = str_replace(" ","-",$b['name']);
            }
        }
        foreach ($data1 as $k=>$v){
            if($k==$kk+1){
                $c = $v;
                $c['uname'] = str_replace(" ","-",$c['name']);
            }
        }
        $this->assign("b",$b);
        $this->assign("c",$c);

        return $this->fetch();
    }
}